#include <QFileDialog>
#include "MainWindow.h"
#include "AboutWindow.h"
#include "ui_MainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    VAL_DIST = 10;      // odleglosc miedzy parametrami

    QList<QLineEdit*> all_lineedit = findChildren<QLineEdit*>();
    foreach (QLineEdit* p_lineedit, all_lineedit)
    {
        p_lineedit->setMaxLength(10);
        p_lineedit->setValidator(new QDoubleValidator(p_lineedit));
    }

    ui->titleLineEdit->setValidator(new QRegExpValidator(this));
    ui->titleLineEdit->setMaxLength(20);
    ui->dpPRMR1lineEdit->setValidator(new QRegExpValidator(this));
    ui->dpPRMR1lineEdit->setMaxLength(20);
    ui->dpPRMR2lineEdit->setValidator(new QRegExpValidator(this));
    ui->dpPRMR2lineEdit->setMaxLength(20);
    ui->dpPRMR3lineEdit->setValidator(new QRegExpValidator(this));
    ui->dpPRMR3lineEdit->setMaxLength(20);
    ui->dpPRMR4lineEdit->setValidator(new QRegExpValidator(this));
    ui->dpPRMR4lineEdit->setMaxLength(20);
    ui->castsi5CITlineEdit->setValidator(new QRegExpValidator(this));
    ui->castsi5CITlineEdit->setMaxLength(20);
    ui->inc1lineEdit->setValidator(new QRegExpValidator(this));
    ui->inc1lineEdit->setMaxLength(20);
    ui->inc2lineEdit->setValidator(new QRegExpValidator(this));
    ui->inc2lineEdit->setMaxLength(20);

    //ui->part4NAMElineEdit->setValidator(new QRegExpValidator(this));
    //ui->part4NAMElineEdit->setMaxLength(20);
/*
    ui->dctABSCISSA1lineEdit->setMaxLength(20);
    ui->dctABSCISSA2lineEdit->setMaxLength(20);
    ui->dctORDINATE1lineEdit->setMaxLength(20);
    ui->dctORDINATE2lineEdit->setMaxLength(20);*/
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_actionOpen_triggered()
{
    QString fileName = QFileDialog::getOpenFileName(this, QString::fromUtf8("Otwórz plik"), ".", tr("Dyn files (*.dyn)"));

    if (fileName != "")
    {
        inFile = fileName;
        Load();
    }
}

void MainWindow::on_actionExit_triggered()
{
    close();
}

void MainWindow::on_actionAbout_triggered()
{
    AboutWindow *aboutWin = new AboutWindow();
    aboutWin->show();
}


void MainWindow::on_actionSaveAs_triggered()
{
    QString fileName = QFileDialog::getSaveFileName(this, QString::fromUtf8("Zapisz plik"), QString("."), tr("DYN Files (*.dyn)"));
    if (!fileName.endsWith(".dyn"))
    {
        fileName.append(".dyn");
    }

    if (fileName != "")
    {
        Save(fileName);
    }
}
